package com.ruoyi.receipt.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receipt.domain.TbCaManager;
import com.ruoyi.receipt.service.ITbCaManagerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 密保录入Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@RestController
@RequestMapping("/receipt/caManager")
public class TbCaManagerController extends BaseController
{
    @Autowired
    private ITbCaManagerService tbCaManagerService;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询密保录入列表
     */
    @PreAuthorize("@ss.hasPermi('receipt:caManager:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCaManager tbCaManager)
    {
        startPage();
        List<TbCaManager> list = tbCaManagerService.selectTbCaManagerList(tbCaManager);
        return getDataTable(list);
    }

    /**
     * 导出密保录入列表
     */
    @PreAuthorize("@ss.hasPermi('receipt:caManager:export')")
    @Log(title = "密保录入", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbCaManager tbCaManager)
    {
        List<TbCaManager> list = tbCaManagerService.selectTbCaManagerList(tbCaManager);
        ExcelUtil<TbCaManager> util = new ExcelUtil<TbCaManager>(TbCaManager.class);
        return util.exportExcel(list, "caManager");
    }

    /**
     * 获取密保录入详细信息
     */
    @PreAuthorize("@ss.hasPermi('receipt:caManager:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbCaManagerService.selectTbCaManagerById(id));
    }

    /**
     * 新增密保录入
     */
    @PreAuthorize("@ss.hasPermi('receipt:caManager:add')")
    @Log(title = "密保录入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCaManager tbCaManager)
    {
        tbCaManager.setId(idWorker.nextId());
        return toAjax(tbCaManagerService.insertTbCaManager(tbCaManager));
    }

    /**
     * 修改密保录入
     */
    @PreAuthorize("@ss.hasPermi('receipt:caManager:edit')")
    @Log(title = "密保录入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCaManager tbCaManager)
    {
        return toAjax(tbCaManagerService.updateTbCaManager(tbCaManager));
    }

    /**
     * 删除密保录入
     */
    @PreAuthorize("@ss.hasPermi('receipt:caManager:remove')")
    @Log(title = "密保录入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCaManagerService.deleteTbCaManagerByIds(ids));
    }
}
